package com.chixing.ih.module.programmer.service.Impl;

import com.chixing.ih.module.programmer.mapper.TechnologyCreditMapper;
import com.chixing.ih.module.programmer.other.DateList;
import com.chixing.ih.module.programmer.pojo.dto.TechnologyCreditDTO;
import com.chixing.ih.module.programmer.pojo.dto.TechnologyCreditListDTO;
import com.chixing.ih.module.programmer.service.ITechnologyCreditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @version 1.0
 * @Author MasterYan
 * @Date 2020/10/4
 * Time: 15:49
 */
@Service
@Transactional
public class TechnologyCreditServiceImpl implements ITechnologyCreditService {

    @Autowired
    TechnologyCreditMapper technologyCreditMapper;

    @Override
    public TechnologyCreditListDTO technologyCredits(long programmerId) {

        TechnologyCreditListDTO technologyCreditListDTO = new TechnologyCreditListDTO();

        List<String> dateList = DateList.getDateList();
        List<Long> chargebackList = new ArrayList<>();
        List<Long> ordList = new ArrayList<>();
        List<Long> posComList = new ArrayList<>();
        List<Long> totalIntegralList = new ArrayList<>();


        List<TechnologyCreditDTO> technologyCreditDTOS1 = technologyCreditMapper.listChargebackOrdNum(programmerId);
        Map<String, Long> map1 = new HashMap<>();
        for (TechnologyCreditDTO credit : technologyCreditDTOS1
        ) {
            map1.put(credit.getDate(), credit.getNumber());
        }
        for (String s : dateList
        ) {
            if (map1.get(s) != null)
                chargebackList.add(map1.get(s));
            else
                chargebackList.add(0l);

        }

        List<TechnologyCreditDTO> technologyCreditDTOS2 = technologyCreditMapper.listOrdNum(programmerId);
        Map<String, Long> map2 = new HashMap<>();
        for (TechnologyCreditDTO credit : technologyCreditDTOS2
        ) {
            map2.put(credit.getDate(), credit.getNumber());
        }
        for (String s : dateList
        ) {
            if (map2.get(s) != null)
                ordList.add(map2.get(s));
            else
                ordList.add(0l);

        }

        List<TechnologyCreditDTO> technologyCreditDTOS3 = technologyCreditMapper.listPosComNum(programmerId);
        Map<String, Long> map3 = new HashMap<>();
        for (TechnologyCreditDTO credit : technologyCreditDTOS3
        ) {
            map3.put(credit.getDate(), credit.getNumber());
        }
        for (String s : dateList
        ) {
            if (map3.get(s) != null)
                posComList.add(map3.get(s));
            else
                posComList.add(0l);

        }

        List<TechnologyCreditDTO> technologyCreditDTOS4 = technologyCreditMapper.listTotalIntegral(programmerId);
        Map<String, Long> map4 = new HashMap<>();
        for (TechnologyCreditDTO credit : technologyCreditDTOS4
        ) {
            map4.put(credit.getDate(), credit.getNumber());
        }
        for (String s : dateList
        ) {
            if (map4.get(s) != null)
                totalIntegralList.add(map4.get(s));
            else
                totalIntegralList.add(0l);

        }
        technologyCreditListDTO.setDateList(dateList);
        technologyCreditListDTO.setChargebackList(chargebackList);
        technologyCreditListDTO.setOrdList(ordList);
        technologyCreditListDTO.setPosComList(posComList);
        technologyCreditListDTO.setTotalIntegralList(totalIntegralList);
        return technologyCreditListDTO;
    }
}
